// 声明一个全局对象Namespace，用来注册命名空间
Namespace = new Object();
// 全局对象仅仅存在register函数，参数为名称空间全路径，如"Grandsoft.GEA"
Namespace.register = function(fullNS)
{
    // 将命名空间切成N部分, 比如Grandsoft、GEA等
    var nsArray = fullNS.split('.');
    var sEval = "";
    var sNS = "";
    for (var i = 0; i < nsArray.length; i++)
    {
        if (i != 0) sNS += ".";
        sNS += nsArray[i];
        // 依次创建构造命名空间对象（假如不存在的话）的语句
        // 比如先创建Grandsoft，然后创建Grandsoft.GEA，依次下去
        sEval += "if (typeof(" + sNS + ") == 'undefined') " + sNS + " = new Object();"
    }
    if (sEval != "") eval(sEval);
}
//上面就是在JavaScript中模拟命名空间机制的完整实现，使用方式如下： 

// 注册命名空间 com.hmsm
Namespace.register("com.hmsm");

// 给数组添加一个包含判断函数
Array.prototype.contains=function(A){
	return (this.indexOf(A) >= 0);
}

/**
 * 	<script type="text/javascript" for="控件ID" event="事件处理函数名">
 * //事件handler
 * alert();
 * </script>	
 * 调用方法 com.hmsm.UploadHMSM($(".dragable")); // 绑定所有可拖拽对象
 * com.hmsm.UploadHMSM by lzyyj
 * Date: 2013-8-16
 * @param {} obj 要绑定拖拽功能的对象或对象集合
 * 
 */
com.hmsm.UploadHMSM = function(id){
	// 确定控件id
	this.oId = "uploadHM";
	if(typeof(id)!="undefined"){
		oId = id;
	}
	
	this.uploadOcx = load(this.oId);
	this.getUserDir = function getUserDir(){
//		return getUploadHM().getUserDir();
		return "uploadOcx="+getAllPrpos(this.uploadOcx);
	}; 
	
	// 初始化结束
	
	this.checkStatus = function(){
		alert("checkStatus");
		this.uploadOcx = $("#"+this.oId)[0];
		if (uploadHM && uploadHM.readyState==4){
			try{
				if(uploadHM.getVersion){
					version = uploadHM.getVersion();
					userPath = uploadHM.getUserDir();
				}else{
					this.uploadOcx = null;
					alert("插件版本异常！");
				}
			}catch(e){
				this.uploadOcx = null;
				alert("插件未正确安装（"+uploadHM+"-"+e+"）");
			}
			
			if(version!="1.0.0.3"){
				alert("当前插件版本["+version+"]太低！");
			}
			if(userPath==""){
				this.uploadOcx = null;
				alert("无效的盘符！");
			}
		}else{
			this.uploadOcx = "";
		}
		
	};
	
	function load(oId){
		var result = null;
		
		if(typeof(oId)!="undefined"){
			result = $("#"+oId)[0];
			if(result==null){
				alert("未找到！"+oId);
				var method = 0;
				try{
					var uploadObject = document.createElement('object');
					uploadObject.id = this.oId;
					uploadObject.classid = "clsid:E5F3CA0B-CB3C-4F76-9FEE-585FBDCCD8CD";
					uploadObject.codebase = "../soft/uploadHM.CAB#version=1,0,0,3";
					uploadObject.width = 0;
					uploadObject.height = 0;
					uploadObject.onerror = loadError;
					uploadObject.onload = loadComplate;

					method = 1;
				}catch (e) {
					var html = "<object id=\""+this.oId+"\" classid=\"clsid:E5F3CA0B-CB3C-4F76-9FEE-585FBDCCD8CD\" codebase=\"../soft/uploadHM.CAB#version=1,0,0,3\" width=\"0\" height=\"0\" onerror=\"alert('error');\" onload=\"alert('成功！');\"></object>";
					method = 2;
				}
				document.body.appendChild(uploadObject);
			}else{
				alert("找到了！"+oId);
			}
		}
		
		return result;
	}

	function FinishScan(){
		this.uploadOcx.FinishScan();
	}
	
	function GetFinishState(){
		return this.uploadOcx.GetFinishState();
	}
	
	function GetUploadNum(){
		return this.uploadOcx.GetUploadNum();
	}
	
	function clearInfo(){
		
	}
	
	function createFile(paths){
		
	}
	
	function deleteFile(paths){
		
	}
	
	function deleteFileAll(paths){
		
	}
	
	function getFileAccount(paths){
		return this.uploadOcx.getFileAccount(paths);
	}
	
	function getPathFileAccount(paths){
		return this.uploadOcx.getPathFileAccount(paths);
	}
	
	function stopFuncAll(){
		
	}
	
	function upload(paths,hmServer,hmServerPath,pars,hmPort){
		return this.uploadOcx.upload(paths,hmServer,hmServerPath,pars,hmPort);
	}
	
	function loadError(){
		this.uploadOcx = null;
		alert("uploadHM 组件加载失败！!");
	}
	
	function loadComplate(){
		alert("uploadHM 组件加载结束！");
	}
	
}
